package com.bgds.sys.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.bgds.sys.api.bean.mars.vo.WaveDataVO;
import com.bgds.sys.api.bean.mos.dto.*;
import com.bgds.sys.api.service.RongZhiService;
import com.bgds.sys.common.pagevo.Result;
import com.bgds.sys.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: warm
 * @Description:
 * @Date: 2020/7/29 13:24
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = "容知数据接口")
@RequestMapping("/mos")
public class MosCotroller {

    @Autowired
    private RongZhiService rongZhiService;

    @RequestMapping(value = "/devices", method = RequestMethod.GET)
    @ApiOperation(value = "容知设备树",notes = "容知设备树",httpMethod = "GET")
    public Result<List<MosDeviceDto>> getDevices(){
        List<MosDeviceDto> devices=  rongZhiService.getMosDevicesTree();
        return new ResultUtil<List<MosDeviceDto>>().setData(devices);
    }

    @RequestMapping(value = "/assets", method = RequestMethod.GET)
    @ApiOperation(value = "容知资产",notes = "容知资产",httpMethod = "GET")

    public Result<List<MosDeviceDto>> getAssets(){
        List<MosDeviceDto> assetsDtos=  rongZhiService.getAllAssets();
        return new ResultUtil<List<MosDeviceDto>>().setData(assetsDtos);
    }
    @RequestMapping(value = "/vibdatas", method = RequestMethod.GET)
    @ApiOperation(value = "获取测量定义趋势数据",notes = "获取测量定义趋势数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "measfId", dataType = "String", value = "测量定义ID"),
            @ApiImplicitParam(name = "minDate", dataType = "String",  value = "起始时间"),
            @ApiImplicitParam(name = "maxDate", dataType = "String",  value = "结束时间"),
            @ApiImplicitParam(name = "limit", dataType = "Integer",  value = "状态"),
    })
    public Result<List<VibdatasDto>> getVibdatas(String measfId, String minDate, String maxDate, Integer limit){
        List<VibdatasDto> vibdatas=  rongZhiService.getVibdatasByParams(measfId,minDate,maxDate,limit);
        return new ResultUtil<List<VibdatasDto>>().setData(vibdatas);
    }

    @RequestMapping(value = "/getOriginalWave", method = RequestMethod.GET)
    @ApiOperation(value = "获取原始波形",notes = "获取原始波形",httpMethod = "GET")

    public Result<List<Float>> getOriginalWave(String waveKey){
        List<Float> vibdatas=  rongZhiService.getOriginalWave(waveKey);
        return new ResultUtil<List<Float>>().setData(vibdatas);
    }
    @RequestMapping(value = "/getCHTemperatures", method = RequestMethod.GET)
    @ApiOperation(value = "通道温度",notes = "通道温度",httpMethod = "GET")

    public Result<TechniqueDto> getChTemperatures(String pointId, String minDate, String maxDate, Integer limit){
        TechniqueDto techniqueDto=  rongZhiService.getChTemperatures(pointId,minDate,maxDate,limit);
        return new ResultUtil<TechniqueDto>().setData(techniqueDto);
    }
    @RequestMapping(value = "/getSpectrumByWaveKey", method = RequestMethod.GET)
    @ApiOperation(value = "获取频谱",notes = "获取频谱",httpMethod = "GET")

    public Result<List<WaveDataVO> > getSpectrumByWaveKey(String waveKey){
        List<WaveDataVO>  waveDataVos =  rongZhiService.getSpectrumByWaveKey(waveKey);
        return new ResultUtil<List<WaveDataVO>>().setData(waveDataVos);
    }

    @RequestMapping(value = "/getCepstrumByWaveKey", method = RequestMethod.GET)
    @ApiOperation(value = "获取倒谱",notes = "获取倒谱",httpMethod = "GET")

    public Result< List<WaveDataVO>> getCepstrumByWaveKey(String waveKey){
        List<WaveDataVO>  waveDataVos=  rongZhiService.getCepstrumByWaveKey(waveKey);
        return new ResultUtil< List<WaveDataVO>>().setData(waveDataVos);
    }

    @RequestMapping(value = "/getEnvolopeByWaveKey", method = RequestMethod.GET)
    @ApiOperation(value = "获取包络谱",notes = "获取包络谱",httpMethod = "GET")

    public Result<List<WaveDataVO>> getEnvolopeByWaveKey(String waveKey, Integer centerRate, Integer bindWidth, Integer widthRate){
        List<WaveDataVO> waveDataVos=  rongZhiService.getEnvolopeByWaveKey(waveKey,centerRate,bindWidth,widthRate);
        return new ResultUtil<List<WaveDataVO>>().setData(waveDataVos);
    }

    @RequestMapping(value = "/getVibWaveByWaveKey", method = RequestMethod.GET)
    @ApiOperation(value = "获取振动波形",notes = "获取振动波形",httpMethod = "GET")

    public Result<List<WaveDataVO>> getVibWaveByWaveKey(String waveKey){
        List<WaveDataVO> waveDataVos=  rongZhiService.getVibWaveByWaveKey(waveKey);
        return new ResultUtil<List<WaveDataVO>>().setData(waveDataVos);
    }

    @RequestMapping(value = "/getLastMeasurement", method = RequestMethod.GET)
    @ApiOperation(value = "获取设备或测点最新的采集数据",notes = "获取设备或测点最新的采集数据",httpMethod = "GET")

    public Result<List<JSONObject>> getLastMeasurement(String deviceIdOrPointId, String dateType){
        List<JSONObject> jsonObjects=  rongZhiService.getLastMeasurement(deviceIdOrPointId,dateType);
        return new ResultUtil<List<JSONObject>>().setData(jsonObjects);
    }


    @RequestMapping(value = "/getMeasurementByPeriod", method = RequestMethod.GET)
    @ApiOperation(value = "获取设备时间区间内的振动读数 开始时间和结束时间距离不能超过1天 最大限制2000条",notes = "获取设备时间区间内的振动读数 开始时间和结束时间距离不能超过1天 最大限制2000条",httpMethod = "GET")

    public Result<MeasurementDto> getMeasurementByPeriod(String deviceId, String minDate, String maxDate){
        MeasurementDto measurementDto=  rongZhiService.getMeasurementByPeriod(deviceId,minDate,maxDate);
        return new ResultUtil<MeasurementDto>().setData(measurementDto);
    }

    @RequestMapping(value = "/getVibSamplingDatas", method = RequestMethod.GET)
    @ApiOperation(value = "获取振动采样值指标趋势数据",notes = "获取振动采样值指标趋势数据",httpMethod = "GET")

    public Result<VibSamplingDataDto> getVibSamplingDatas(String pointId, String indexCode, String minDate, String maxDate){
        VibSamplingDataDto vibSamplingDataDto=  rongZhiService.getVibSamplingDatas(pointId,indexCode,minDate,maxDate);
        return new ResultUtil<VibSamplingDataDto>().setData(vibSamplingDataDto);
    }

    @RequestMapping(value = "/getTsDatas", method = RequestMethod.GET)
    @ApiOperation(value = "工艺数据",notes = "工艺数据",httpMethod = "GET")

    public Result<TechniqueDto> getTsDatas(String assetid, Integer isOriginalData, String minDate, String maxDate){
        TechniqueDto techniqueDto=  rongZhiService.getTsDatas(assetid,isOriginalData,minDate,maxDate);
        return new ResultUtil<TechniqueDto>().setData(techniqueDto);
    }
}